package com.wys.ws_im.controller;

import com.wys.ws_im.exception.FrameErrorCodeEnums;
import com.wys.ws_im.exception.FrameRuntimeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Slf4j
@Controller
public class LoginState {

    /**
     * 检测账号是否登录
     * @param uid
     * @param request
     * @return
     */
    public Boolean loginState(Integer uid, HttpServletRequest request) {

        if (uid == null){
            throw new FrameRuntimeException(FrameErrorCodeEnums.BIND_ARGS_ERROR);
        }
        HttpSession sessoin = request.getSession();//这就是session的创建
        System.out.println(sessoin.getId());
        Object sessionBrowser = sessoin.getAttribute(uid.toString());
        if (sessionBrowser == null) {
            throw new FrameRuntimeException(FrameErrorCodeEnums.NOT_LOGIN_ERROR);
        }

        return Boolean.TRUE;
    }

}
